package com.heima.article.listen;

import com.heima.model.common.constants.article.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HotArticleScoreListener {

    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 用于将监听到的行为数据
     * 存入到redis队列中 等待计算
     **/
    @RabbitListener(queuesToDeclare = @Queue(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE))
    public void articleBehaviorHandler(String articleMess){
        log.info(" 文章实时更新队列: 接收到文章行为变化 消息内容: {}",articleMess);
        redisTemplate.opsForList().rightPush(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_LIST,articleMess);
    }
}
